import 'package:flutter/animation.dart';
import 'package:flutter/material.dart';


class LogoApp extends StatefulWidget {
  AnimationController controllers;
  _AnimationApp __animationApp;
  @override
  State<StatefulWidget> createState() {
    // TODO: implement createState
    __animationApp=_AnimationApp();
    return __animationApp;
  }
  dispose(){
    __animationApp?.dispose();
  }
}
class _AnimationApp extends State<LogoApp> with SingleTickerProviderStateMixin {

  Animation<EdgeInsets> movement;
  AnimationController controller;


  /*初始化状态*/
  initState() {
    super.initState();


    /*创建动画控制类对象*/
    controller = new AnimationController(
        duration: const Duration(milliseconds: 2000),
        vsync: this);

    movement = EdgeInsetsTween(
      begin: EdgeInsets.only(top: 0.0),
      end: EdgeInsets.only(top: 300.0),
    ).animate(
      CurvedAnimation(
        parent: controller,
        curve: Interval(
          0.25,
          1,
          curve: Curves.fastOutSlowIn,
        ),
      ),
    );
    movement.addStatusListener((status){
      if (status == AnimationStatus.completed) {
        controller.reverse();
      } else if (status == AnimationStatus.dismissed) {
        controller.forward();
      }
    });

    controller.forward();       //执行动画
  }

  Widget _buildAni(BuildContext context, Widget child) {

    return new Container(
      padding: movement.value,
      // transform: Matrix4.identity()..rotateZ(rotate.value),
      child: new Opacity(
        opacity: 1,
        child: new Container(
          height: 3,
          color: Colors.blue,
        ),
      ),
    );
  }


  @override
  Widget build(BuildContext context) {
    return new AnimatedBuilder(animation: controller, builder: _buildAni);
  }

  _startAnimation(){
    setState(() {
      if (controller.status == AnimationStatus.completed) {
        controller.reverse();
      } else if (controller.status == AnimationStatus.dismissed) {
        controller.forward();
      }

    });

  }

  @override
  dispose() {
    //销毁控制器对象
    controller?.dispose();
    super.dispose();
  }
}

